const path = require("path");
const resolve = (dir) => path.join(__dirname, dir);
module.exports = {
  publicPath: process.env.NODE_ENV === "production" ? "/vueadminwork/" : "/",
  assetsDir: "static",
  outputDir: "dist/vueadminwork",
  lintOnSave: false,
  productionSourceMap: false,
  chainWebpack: (config) => {
    /* svg-sprite-loader 相关配置 */
    // 清空默认svg规则针对svg的路径的配置
    config.module.rule("svg").exclude.add(resolve("src/icons")).end();
    //针对svg文件添加svg-sprite-loader规则
    config.module
      .rule("svg-sprite-loader-rule")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({ symbolId: "icon-[name]" })
      .end();
    //清空已构建文件
    config.output.clean = true;
  },
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === "production") {
      config.optimization = {
        minimize: true,
        splitChunks: {
          chunks: "all",
          cacheGroups: {
            libs: {
              name: "chunk-libs",
              test: /[\\/]node_modules[\\/]/,
              priority: 10,
              chunks: "initial", // only package third parties that are initially dependent
            },
            elementUI: {
              name: "chunk-elementUI", // split elementUI into a single package
              priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
              test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
            },
            commons: {
              name: "chunk-commons",
              test: path.resolve(__dirname, "src/components"),
              minChunks: 3, //  minimum common number
              priority: 5,
              reuseExistingChunk: true,
            },
          },
        },
      };
    } else {
      config.optimization = {
        minimize: false,
      };
    }
  },
  pluginOptions: {
    // "style-resources-loader": {
    //   preProcessor: "scss",
    //   patterns: [
    //     // path.resolve(__dirname, "src/assets/styles/variables.scss"),
    //     // path.resolve(__dirname, "src/assets/styles/transition.scss"),
    //   ],
    // },
  },
  devServer: {
    host: "0.0.0.0",
    port: 5567,
    open: true,
    proxy: undefined,
    disableHostCheck: true,
  },
};
